home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2000 July / CD 3 / redhat-6.2.iso / RedHat / instimage / usr / lib / anaconda / iw / silo.py < prev    next >
Encoding:
Python Source  |  2000-03-08  |  8.4 KB  |  309 lines

  1. from iw import *
  2. from gtk import *
  3. from translate import _
  4. from xpms import SMALL_CHECK
  5. import GdkImlib
  6.  
  7. class SiloWindow (InstallWindow):
  8.     foo = GdkImlib.create_image_from_xpm (SMALL_CHECK)
  9.     foo.render()
  10.     checkMark = foo.make_pixmap()
  11.     del foo
  12.  
  13.     def __init__ (self, ics):
  14.     InstallWindow.__init__ (self, ics)
  15.  
  16.     ics.readHTML ("silo")
  17.  
  18.     ics.setTitle (_("Silo Configuration"))
  19.     ics.setNextEnabled (1)
  20.     self.type = None
  21.     self.bootdisk = None
  22.     self.silo = None
  23.     self.linuxAlias = None
  24.     self.linuxAliasLabel = None
  25.     self.bootDevice = None
  26.  
  27.     def getNext (self):
  28.     # XXX
  29.     if not self.bootdisk:
  30.         if self.todo.silo.hasUsableFloppy() == 2:
  31.         self.todo.bootdisk = 1
  32.         else:
  33.         self.todo.bootdisk = 0
  34.         return None
  35.  
  36.     if self.bootdisk.get_active ():
  37.         self.todo.bootdisk = 1
  38.     else:
  39.         self.todo.bootdisk = 0
  40.  
  41.     if self.silo.get_active ():
  42.         self.todo.silo.setDevice(None)
  43.     elif self.todo.silo.allowSiloLocationConfig(self.todo.fstab):
  44.         if self.mbr.get_active ():
  45.         self.todo.silo.setDevice("mbr")
  46.         else:
  47.         self.todo.silo.setDevice("partition")
  48.  
  49.     self.todo.silo.setAppend(self.appendEntry.get_text())
  50.     self.todo.silo.setSiloImages(self.images)
  51.  
  52.     linuxAlias = 0
  53.     bootDevice = 0
  54.     if self.linuxAlias.get_active ():
  55.         linuxAlias = 1
  56.     if self.bootDevice.get_active ():
  57.         bootDevice = 1
  58.         
  59.     self.todo.silo.setPROM(linuxAlias, bootDevice)
  60.  
  61.     def typeName(self, type):
  62.     if (type == 2):
  63.         return "Linux Native"
  64.     elif (type == 6):
  65.         return "UFS"
  66.     else:
  67.         return "Other"
  68.  
  69.     def toggled (self, widget, *args):
  70.     if widget.get_active ():
  71.         state = FALSE
  72.     else:
  73.         state = TRUE
  74.  
  75.     for n in [ self.radioBox, self.editBox, self.imageList ]:
  76.         n.set_sensitive (state)
  77.  
  78.     def mbr_toggled (self, widget, *args):
  79.     if widget.get_active ():
  80.         part = self.mbrpart
  81.     else:
  82.         part = self.bootpart
  83.     prompath = self.todo.silo.disk2PromPath(part)
  84.     if prompath and len(prompath) > 0:
  85.         self.linuxAliasLabel.set_text ("linux " + prompath)
  86.         if self.todo.silo.hasAliases():
  87.         self.linuxAliasLabel.set_sensitive (TRUE)
  88.         self.linuxAlias.set_sensitive (TRUE)
  89.         return
  90.     self.linuxAliasLabel.set_sensitive (FALSE)
  91.     self.linuxAlias.set_sensitive (FALSE)
  92.  
  93.     def labelUpdated(self, *args):
  94.     index = self.imageList.selection[0]
  95.     device = self.imageList.get_text(index, 1)
  96.  
  97.     label = self.labelEntry.get_text()
  98.     self.imageList.set_text(index, 3, label)
  99.  
  100.     if label:
  101.         self.defaultCheck.set_sensitive (TRUE)
  102.     else:
  103.         self.defaultCheck.set_sensitive (FALSE)
  104.  
  105.     def defaultUpdated(self, *args):
  106.     if self.ignoreSignals: return
  107.  
  108.     index = self.imageList.selection[0]
  109.  
  110.     if self.defaultCheck.get_active():
  111.         if self.default != None:
  112.         self.imageList.set_text(self.default, 0, "")
  113.  
  114.         self.imageList.set_pixmap(index, 0, self.checkMark)
  115.         self.default = index
  116.     else:
  117.         self.imageList.set_text(index, 0, "")
  118.         self.default = None
  119.  
  120.     def labelSelected(self, *args):
  121.     index = self.imageList.selection[0]
  122.     device = self.imageList.get_text(index, 1)
  123.     label = self.imageList.get_text(index, 3)
  124.  
  125.     self.deviceLabel.set_text(_("Partition") + ": " + device)
  126.     device = device[5:]
  127.  
  128.     type = self.images[device][1]
  129.  
  130.     self.typeLabel.set_text(_("Type") + ":" + self.typeName(type))
  131.     self.labelEntry.set_text(label)
  132.  
  133.     if not label:
  134.         self.defaultCheck.set_sensitive (FALSE)
  135.  
  136.     self.ignoreSignals = 1
  137.     if index == self.default:
  138.         self.defaultCheck.set_active(1)
  139.     else:
  140.         self.defaultCheck.set_active(0)
  141.     self.ignoreSignals = 0
  142.  
  143.     def getScreen (self):
  144.     (self.images, defaultLabel) = self.todo.silo.getSiloImages(self.todo.fstab)
  145.     self.ignoreSignals = 0
  146.  
  147.     (mount, dev, fstype, format, size) = self.todo.fstab.mountList()[0]
  148.     if mount != '/': return None
  149.  
  150.     self.bootpart = self.todo.fstab.getBootDevice()
  151.     self.mbrpart = self.todo.silo.getMbrDevice(self.todo.fstab)
  152.     format = "/dev/%s"
  153.  
  154.     self.radioBox = GtkTable(2, 7)
  155.     self.radioBox.set_border_width (5)
  156.     
  157.     spacer = GtkLabel("")
  158.     spacer.set_usize(10, 1)
  159.     self.radioBox.attach(spacer, 0, 1, 2, 4, FALSE)
  160.  
  161.     label = GtkLabel(_("Install SILO boot record on:"))
  162.     label.set_alignment(0.0, 0.5)
  163.     self.radioBox.attach(label, 0, 2, 1, 2)
  164.  
  165.     mbrpart = self.mbrpart
  166.     if self.bootpart[:2] == "md":
  167.         mbrpart = self.bootpart
  168.     # FIXME: Should be Master Boot Records (MBR) in the RAID1 case
  169.     self.mbr = GtkRadioButton(None, 
  170.         ("/dev/%s %s" % (mbrpart, _("Master Boot Record (MBR)"))))
  171.     part = GtkRadioButton(self.mbr,
  172.         ("/dev/%s %s" % (self.bootpart, 
  173.         _("First sector of boot partition"))))
  174.     self.radioBox.attach(self.mbr, 1, 2, 2, 3)
  175.     self.radioBox.attach(part, 1, 2, 3, 4)
  176.  
  177.     self.linuxAlias = GtkCheckButton(
  178.         _("Create PROM alias") + ":")
  179.     if (self.todo.silo.hasAliases()):
  180.         self.linuxAlias.set_active (TRUE)
  181.     else:
  182.         self.linuxAlias.set_active (FALSE)
  183.     self.linuxAliasLabel = GtkLabel("")
  184.     self.mbr_toggled(self.mbr)
  185.     tempBox = GtkHBox (FALSE, 5)
  186.     tempBox.pack_start(self.linuxAlias)
  187.     tempBox.pack_start(self.linuxAliasLabel)
  188.     self.radioBox.attach(tempBox, 0, 2, 4, 5)
  189.  
  190.     self.mbr.connect("toggled", self.mbr_toggled)
  191.     if self.bootpart[:2] == "md":
  192.         self.mbr.set_active (TRUE)
  193.         label.set_sensitive (FALSE)
  194.         self.mbr.set_sensitive (FALSE)
  195.         part.set_sensitive (FALSE)
  196.     if self.todo.silo.getSiloMbrDefault(self.todo.fstab) == 'mbr':
  197.         self.mbr.set_active (TRUE)
  198.     else:
  199.         part.set_active (TRUE);
  200.  
  201.     self.bootDevice = GtkCheckButton(_("Set default PROM boot device to linux"))
  202.     self.radioBox.attach(self.bootDevice, 0, 2, 5, 6)
  203.     self.bootDevice.set_active (TRUE)
  204.  
  205.     label = GtkLabel(_("Kernel parameters") + ":")
  206.     label.set_alignment(0.0, 0.5)
  207.     self.appendEntry = GtkEntry(15)
  208.     if self.todo.silo.getAppend():
  209.         self.appendEntry.set_text(self.todo.silo.getAppend())
  210.     box = GtkHBox(FALSE, 5)
  211.     box.pack_start(label)
  212.     box.pack_start(self.appendEntry)
  213.     alignment = GtkAlignment()
  214.     alignment.set(0.0, 0.5, 0, 1.0)
  215.     alignment.add(box)
  216.     self.radioBox.attach(alignment, 0, 2, 6, 7)
  217.     
  218.     box = GtkVBox (FALSE, 0)
  219.  
  220.     topBox = GtkHBox (FALSE, 2)
  221.     optionBox = GtkVBox (FALSE, 5)
  222.     optionBox.set_border_width (5)
  223.     self.bootdisk = GtkCheckButton (_("Create boot disk"))
  224.     floppy = self.todo.silo.hasUsableFloppy()
  225.     if floppy == 2:
  226.         self.bootdisk.set_active (TRUE)
  227.     else:
  228.         self.bootdisk.set_active (FALSE)
  229.     if floppy == 0:
  230.         self.bootdisk.set_sensitive (FALSE)
  231.     optionBox.pack_start (self.bootdisk)
  232.  
  233.     self.silo = GtkCheckButton (_("Do not install SILO"))
  234.     self.silo.set_active (FALSE)
  235.     self.silo.connect ("toggled", self.toggled)
  236.     optionBox.pack_start (self.silo, FALSE)
  237.     topBox.pack_start (optionBox)
  238.  
  239.     im = self.ics.readPixmap ("silo.png")
  240.     if im:
  241.         im.render ()
  242.         pix = im.make_pixmap ()
  243.         a = GtkAlignment ()
  244.         a.add (pix)
  245.         a.set (1.0, 0.0, 0.0, 0.0)
  246.         topBox.pack_start (a, FALSE)
  247.  
  248.     box.pack_start (topBox, FALSE)
  249.  
  250.     box.pack_start (GtkHSeparator (), FALSE)
  251.     box.pack_start (self.radioBox, FALSE)
  252.  
  253.     self.imageList = GtkCList (4,
  254.         ( _("Default"), _("Device"), _("Partition type"), _("Boot label")))
  255.     self.imageList.set_selection_mode (SELECTION_BROWSE)
  256.  
  257.     sortedKeys = self.images.keys()
  258.     sortedKeys.sort()
  259.  
  260.     self.default = None
  261.     count = 0
  262.     for n in sortedKeys:
  263.         (label, type) = self.images[n]
  264.         self.imageList.append(("", "/dev/" + n, self.typeName(type), 
  265.                     label))
  266.         if (label == defaultLabel):
  267.         self.default = count
  268.         self.imageList.set_pixmap(count, 0, self.checkMark)
  269.         count = count + 1
  270.  
  271.     self.imageList.columns_autosize ()
  272.     self.imageList.column_title_passive (1)
  273.     self.imageList.set_border_width (5)
  274.     self.imageList.connect("select_row", self.labelSelected)
  275.     self.imageList.set_column_justification(2, JUSTIFY_CENTER)
  276.  
  277.     self.deviceLabel = GtkLabel(_("Partition") + ":")
  278.     self.typeLabel = GtkLabel(_("Type") + ":")
  279.  
  280.     tempBox = GtkHBox(TRUE)
  281.     self.deviceLabel.set_alignment(0.0, 0.0)
  282.     self.typeLabel.set_alignment(0.0, 0.0)
  283.     tempBox.pack_start(self.deviceLabel, FALSE)
  284.     tempBox.pack_start(self.typeLabel, FALSE)
  285.     self.defaultCheck = GtkCheckButton("Default boot image")
  286.     self.defaultCheck.connect("toggled", self.defaultUpdated)
  287.  
  288.     # Alliteration!
  289.     self.labelLabel = GtkLabel(_("Boot label") + ":")
  290.     self.labelEntry = GtkEntry(15)
  291.     self.labelEntry.connect("changed", self.labelUpdated)
  292.  
  293.     tempBox2 = GtkHBox(FALSE, 5)
  294.     self.labelLabel.set_alignment(0.0, 0.5)
  295.     tempBox2.pack_start(self.labelLabel, FALSE)
  296.     tempBox2.pack_start(self.labelEntry, FALSE)
  297.  
  298.     self.editBox = GtkVBox ()
  299.     self.editBox.pack_start (tempBox, FALSE)
  300.     self.editBox.pack_start (self.defaultCheck, FALSE)
  301.     self.editBox.pack_start (tempBox2, FALSE)
  302.     self.editBox.set_border_width (5)
  303.  
  304.     box.pack_start (GtkHSeparator (), FALSE)
  305.     box.pack_start (self.editBox, FALSE)
  306.     box.pack_start (self.imageList, TRUE)
  307.  
  308.     return box
  309.